<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Title</title>
</head>
<body>
<script>
  // 继承： 子类不影响父类，子类可以继承父类的一些功能（代码复用）
  // 属性的继承：调用父类的构造函数 采用 call
  // 方法的继承：for in 拷贝继承

  function Aa(name, sex) {
    this.name = name;
    this.sex = sex;
  }

  Aa.prototype.show = function () {
    console.log(this.name, this.sex);
  };
  let a1 = new Aa("max", "boy");

  function Ab(name, sex, age) {
    Aa.call(this, name, sex);
    this.age = age;
  }

  // Ab.prototype = Aa.prototype;
  extend(Ab.prototype, Aa.prototype);

  let b1 = new Ab("ben", 'boy', 12);

  // b1.show();
  Ab.prototype.showName = function () {
  };

  console.log(Aa.prototype);
  console.log(Ab.prototype);

  function extend(obj1, obj2) {
    for (let attr in obj2) {
      obj1[attr] = obj2[attr];
    }
  }
</script>
</body>
</html>
